package com.wanho.java157.controller;

import com.wanho.java157.result.R;
import com.wanho.java158.CustomerService;
import com.wanho.java157.vo.CustomerVo;
import org.springframework.web.bind.annotation.*;



import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api/core/customer")
public class CustomerController extends BaseContoller {
    @Resource
    private CustomerService customerService;

    @GetMapping("/index")
    public R listAll() {
        List<CustomerVo> customerVoList = customerService.selectAll();
        return R.ok().data("list", customerVoList).message("获取列表成功");
    }


    @DeleteMapping("/remove/{customerId}")
    public R removeById(
            @PathVariable Integer customerId) {
        boolean result = customerService.delete(customerId);
        if (result) {
            return R.ok().message("删除成功");
        } else {
            return R.error().message("删除失败");
        }
    }


    @PutMapping("/update")
    public R updateById(
            @RequestBody CustomerVo customerVo){
        customerVo.getCustomerName();

        boolean result = customerService.update(customerVo) ;
        if(result){
            return R.ok().message("更新成功");
        }else{
            return R.error().message("更新失败");
        }
    }


}